package com.fz.dao;

import com.fz.entity.Student;
import com.fz.mapper.StudentMapper;
import com.fz.mybatis.MyBatisHelper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017-08-25.
 */
public class StudentDAO implements StudentMapper {

    private SqlSession session=new MyBatisHelper().getSession();
    private StudentMapper sdao;
    public StudentDAO(){
        this.sdao=session.getMapper(StudentMapper.class);
    }
    public List<Student> queryall() {
        return this.sdao.queryall();
    }

    public int deleteById(int id) {
        int num=0;
        num=this.sdao.deleteById(id);
        this.session.commit();
        return num;
    }

    public List<Student> queryByName(String name) {
        return this.sdao.queryByName(name);
    }

    public int count() {
        return this.sdao.count();
    }

    public Map<String, Object> showById(int id) {
        return this.sdao.showById(id);
    }

    public List<Map<String, Object>> show() {
        return this.sdao.show();
    }

    public int deleteAll() {
        //如果设计对数据库数据进行变动，最好这样写
        int num=0;
        num=this.sdao.deleteAll();
        this.session.commit();
        return num;
    }

    //利用占位符的方式进行数据添加


    public int adds(String name, String score, String address) {
        int num=0;
        num=this.sdao.adds(name,score,address);
        this.session.commit();
        return num;
    }
}
